import { tooltip, seriesConfig, legendConfig } from './pieParams'

// 告警等级饼图
export const alarmLevelPie = (seriesData) => {

  let color = '#2f4159'
  if (seriesData.length < 1) {
    seriesData.push({
      name: '',
      value: 0
    })
  } else {
    // 判断是否有值 
    const isZero = seriesData.every(i=>i.value === 0)
    color =isZero?['#2f4159','#2f4159','#2f4159'] : ['#ffbc01','#ffec7b','#ff5500']   //2 3 1
  }

  const { clientWidth:w } = document.body
  console.log('seriesData:',seriesData)
  return {
    title: {
      text: '告警',
      subtext: '等级',
      textAlign: 'center',
      textStyle: {
        color: '#fff',
        fontSize: w/1920 * 20,
        align: 'right',
        rich: {
          align: 'right'
        }
      },
      subtextStyle: {
        color: '#fff',
        fontSize: w/1920 * 20,
        align: 'center',
        rich: {
          align: 'center'
        }
      },
      top: '39.6%',
      left: '38.2%'
    },
    tooltip,
    color,
    legend: {
      ...legendConfig,
      right: '0%',
      data: ['一级告警', '二级告警', '三级告警']
    },

    series: [

      {
        ...seriesConfig,
        data: seriesData
      }
    ]
  }
  
}